package com.anlu.base.function.enums;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import com.anlu.base.enums.SuperCodeMsg;
import com.anlu.base.enums.SuperEnumUtil;
import com.anlu.base.function.mode.FormComponentValueBaseBO;
import lombok.Getter;

import java.util.List;
import java.util.function.Function;

@Getter
public enum FunEnum  implements SuperCodeMsg {

    TEXT("文本",ValueFunction.Text),
    SELECT("选择",ValueFunction.SELECT),
    BOOLEAN("布尔",ValueFunction.BOOLEAN);


    FunEnum(String msg, Function<String,FormComponentValueBaseBO> function) {
        this.code = this.name();
        this.msg = msg;
        this.function = function;
    }

    private final String code;
    private final String msg;

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public Function<String, FormComponentValueBaseBO> getFunction() {
        return function;
    }

    private Function<String,FormComponentValueBaseBO> function;

    public static FunEnum codeOf(String code){
        return SuperEnumUtil.codeOf(code,FunEnum.class);
    }


    public interface ValueFunction{
        Function<String, FormComponentValueBaseBO> Text = str -> JSON.parseObject(str, new TypeReference<FormComponentValueBaseBO<String>>() {
        });

        Function<String, FormComponentValueBaseBO> BOOLEAN = str -> JSON.parseObject(str, new TypeReference<FormComponentValueBaseBO<Boolean>>() {
        });

        Function<String, FormComponentValueBaseBO> SELECT = str -> JSON.parseObject(str, new TypeReference<FormComponentValueBaseBO<List<String>>>() {
        });

    }

    public interface X {
        String TEXT = "TEXT";
        String NUM = "NUM";
        String RATIO = "RATIO";
        String DATE = "DATE";
        String DATE_RANGE = "DATE_RANGE";
        String TIME = "TIME";
        String TIME_RANGE = "TIME_RANGE";
        String SELECT = "SELECT";
        String BOOLEAN = "BOOLEAN";
        String TABLE = "TABLE";
        String CLIENT_ANALYSIS = "CLIENT_ANALYSIS";
    }

}
